package com.kh.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.dao.RoleDao;
import com.kh.dao.UserDao;
import com.kh.pojo.KHUser;
import com.kh.pojo.RolePoJo;
import com.kh.utils.Tools;

@Service
@Transactional
public class UserService {
	@Autowired
	UserDao userDao;

	@Autowired
	RoleDao roleDao;

	public List<KHUser> getUserList(KHUser user) {
		List<KHUser> userList = userDao.getUserList(user);
		return userList;
	}

	public KHUser getUserByStaffNo(String staffNo) {
		KHUser user = new KHUser();
		user.setStaffNo(staffNo);
		List<KHUser> userList = getUserList(user);
		return !userList.isEmpty() ? userList.get(0) : null;
	}

	public Long getUserCount(KHUser user) {
		return userDao.getUserCount(user);
	}

	public void saveUser(KHUser user) {
		userDao.saveUser(user);
	}

	// ------------------------角色---------------------------------------
	public List<RolePoJo> getRoleList() {
		return roleDao.getRoleList(null);
	}

	public void saveRole(RolePoJo role) {
		role.setId(Tools.getRandom());
		roleDao.saveRole(role);
	}
}
